﻿using System.Collections.Generic;
using System.Web.Services;
using ClientAdminServerWS.DataTypes;
using DataAccess;
using DataAccess.DataAccess;
using DataAccess.DataModel;

namespace ClientAdminServerWS
{
    /// <summary>
    /// Summary description for ClientInformationService
    /// </summary>
    [WebService(Namespace = "http://ClientAdmin/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class ClientAdminService : System.Web.Services.WebService
    {

        [WebMethod]
        public ClientInfoDTO GetClientInformation(int clientId)
        {
            DataAccessClass dataAccess = new DataAccessClass();
            User user = dataAccess.ObtenerUsuario(clientId);
            if (user != null)
            {
                ClientInfoDTO clientInfo = new ClientInfoDTO()
                {
                    balance = user.SaldoPrepago,
                    IsActive = user.Activo,
                    Name = user.UserName,
                    Prepaid = user.Prepago,
                    UserId = user.UserId
                };
                List<Trip> trips = dataAccess.ObtenerViajesUsuario(clientId);

                trips.ForEach(trip => clientInfo.Trips.Add(new TripDTO() { Charge = trip.CostoViaje, Distance = trip.Kilometraje, Status = (TripStatus)trip.Estado, TripId = trip.ViajeId }));

                return clientInfo;
            }
            return null;
        }

        [WebMethod]
        public bool AddCredit(int clientId, decimal newCredit)
        {
            DataAccessClass dataAccess = new DataAccessClass();
            return dataAccess.ModificarUsuario(clientId, true, newCredit);
        }
    }
}
